﻿using Manage.Traceability.Domain;
using Manage.Traceability.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;

namespace Manage.Traceability.Api.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly ISqlSugarClient db;

        public UserController(ISqlSugarClient db)
        {
            this.db = db;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<UserModel> Login(string username,string pwd)
        {
            var list= db.Queryable<UserModel>().Where(x => x.UserName == username).First();
            if(list==null)
            {
                return ApiResult<UserModel>.Fail("用户名不存在");
            }
            if(list.UserPwd!=pwd)
            {
                return ApiResult<UserModel>.Fail("密码错误");
            }
            return ApiResult<UserModel>.Success("登录成功",list);
        }
    }
}
